/*
 * Copyright (C) 2023 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.templateproject.http;

import android.text.TextUtils;
import androidx.exifinterface.media.ExifInterface;
//import com.jcds.common.base.IBaseView;
//import com.jcds.common.net.BaseResponse;
//import com.jcds.common.net.exception.ApiException;
//import com.taobao.accs.common.Constants;
import com.xuexiang.templateproject.presenter.IBaseView;
import com.xuexiang.xhttp2.exception.ApiException;

//import d.e.a.j.e;
//import f.a.c0.c;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;

import io.reactivex.observers.DisposableObserver;
import kotlin.Metadata;
//import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import retrofit2.HttpException;

/* compiled from: BaseObsrver.kt */
//@Metadata(d1 = {"\u0000:\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u0003\n\u0002\b\b\b&\u0018\u0000*\u0004\b\u0000\u0010\u00012\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u0002H\u00010\u00030\u0002B\u0017\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\b\b\u0002\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\b\u0010\n\u001a\u00020\u000bH\u0016J\u001a\u0010\f\u001a\u00020\u000b2\u0006\u0010\r\u001a\u00020\u000e2\b\u0010\u000f\u001a\u0004\u0018\u00010\u0010H\u0016J\u0010\u0010\f\u001a\u00020\u000b2\u0006\u0010\u0011\u001a\u00020\u0012H\u0016J\u0016\u0010\u0013\u001a\u00020\u000b2\f\u0010\u0014\u001a\b\u0012\u0004\u0012\u00028\u00000\u0003H\u0016J\b\u0010\u0015\u001a\u00020\u000bH\u0014J\u0017\u0010\u0016\u001a\u00020\u000b2\b\u0010\u0014\u001a\u0004\u0018\u00018\u0000H&¢\u0006\u0002\u0010\u0017J\u0010\u0010\u0018\u001a\u00020\u000b2\u0006\u0010\u0019\u001a\u00020\u0010H\u0016R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\t\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0004\u001a\u0004\u0018\u00010\u0005X\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006\u001a"}, d2 = {"Lcom/jcds/common/rx/scheduler/BaseObsrver;", ExifInterface.GPS_DIRECTION_TRUE, "Lio/reactivex/observers/DisposableObserver;", "Lcom/jcds/common/net/BaseResponse;", "v", "Lcom/jcds/common/base/IBaseView;", "isHidden", "", "(Lcom/jcds/common/base/IBaseView;Z)V", "resultNull", "onComplete", "", "onError", Constants.KEY_HTTP_CODE, "", "msg", "", e.u, "", "onNext", "t", "onStart", "onSuccess", "(Ljava/lang/Object;)V", "onSuccessMessage", "message", "common_release"}, k = 1, mv = {1, 7, 1}, xi = 48)
/* loaded from: classes.dex */
public abstract class BaseObsrver<T> extends DisposableObserver<BaseResponse<T>> {
    private boolean isHidden;
    private boolean resultNull;
    @Nullable
    private IBaseView v;

    public /* synthetic */ BaseObsrver(IBaseView iBaseView, boolean z, int i2) {
        this(iBaseView, (i2 & 2) != 0 ? true : z);
    }

    @Override // f.a.r
    public void onComplete() {
    }

    @Override // f.a.r
    public void onError(@NotNull Throwable e2) {
        Intrinsics.checkNotNullParameter(e2, "e");
        if (this.isHidden) {
            IBaseView iBaseView = this.v;
            Intrinsics.checkNotNull(iBaseView);
            iBaseView.dismissLoading();
        }
        if ((e2 instanceof HttpException) || (e2 instanceof SocketTimeoutException) || (e2 instanceof IOException) || (e2 instanceof ConnectException)) {
            onError(0, "网络错误，请稍后再试");
        } else if (e2 instanceof ApiException) {
            onError(((ApiException) e2).getCode(), e2.getMessage());
        } else {
            onError(0, e2.getMessage());
        }
    }
//
//    @Override // f.a.r
//    public /* bridge */ /* synthetic */ void onNext(Object obj) {
//        onNext((BaseResponse) ((BaseResponse) obj));
//    }

    @Override // f.a.c0.c
    public void onStart() {
        super.onStart();
    }

    public abstract void onSuccess(@Nullable T t);

    public void onSuccessMessage(@NotNull String message) {
        Intrinsics.checkNotNullParameter(message, "message");
    }

    public BaseObsrver(@NotNull IBaseView v, boolean z) {
        Intrinsics.checkNotNullParameter(v, "v");
        this.resultNull = true;
        this.isHidden = true;
        this.isHidden = z;
        this.v = v;
    }

    public void onNext(@NotNull BaseResponse<T> t) {
        Intrinsics.checkNotNullParameter(t, "t");
        if (this.isHidden) {
            IBaseView iBaseView = this.v;
            Intrinsics.checkNotNull(iBaseView);
            iBaseView.dismissLoading();
        }
        boolean z = false;
        this.resultNull = false;
        if (t.getErrCode() == 0) {
            onSuccess(t.getContent());
            String errMsg = t.getErrMsg();
            if (errMsg == null || errMsg.length() == 0) {
                z = true;
            }
            if (!z) {
                onSuccessMessage(t.getErrMsg());
                return;
            }
            return;
        }
        onError(t.getErrCode(), t.getErrMsg());
    }

    public void onError(int i2, @Nullable String str) {
        if (TextUtils.isEmpty(str)) {
            IBaseView iBaseView = this.v;
            Intrinsics.checkNotNull(iBaseView);
            iBaseView.bizError("", i2);
            return;
        }
        IBaseView iBaseView2 = this.v;
        Intrinsics.checkNotNull(iBaseView2);
        Intrinsics.checkNotNull(str);
        iBaseView2.bizError(str, i2);
    }
}